package com.example.topguli;

import java.util.concurrent.locks.ReentrantLock;

public class FailLockAndNoFailLock {
    private static Integer ticketNum=30;
   private static ReentrantLock reentrantLock = new ReentrantLock(true);
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            new Thread(()->{
                while (ticketNum > 0) {
                reentrantLock.lock();
                       try {
                               System.out.println(Thread.currentThread().getName() + "=>" + (ticketNum--));
                           }catch (Exception e){
                           e.printStackTrace();
                       }finally {
                           reentrantLock.unlock();
                       }
                    if(ticketNum==0){
                        break;
                    }
                }
            }).start();
        }
    }

}
